<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #video="{ record }">
        <!-- 对标题加上 tag -->
        <a-button @click="handleClick(record)">查看视频</a-button>
      </template>
    </ma-crud>
    <a-modal v-model:visible="visible" @ok="handleOk" @cancel="handleCancel" width="700px">
      <template #title>
        {{ records.title }}
      </template>
      <a :href="records.video" target="_blank">点我查看</a>
      <video :src="records.video"></video>
    </a-modal>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import temblorPopularAnimation from '@/api/temblor/temblorPopularAnimation'
import {Message} from '@arco-design/web-vue'

const crudRef = ref()
const visible = ref(false);
const records = ref({})
const handleClick = (record) => {
  records.value = record;
  visible.value = true;
};
const handleOk = () => {
  visible.value = false;
};
const handleCancel = () => {
  visible.value = false;
}

const numberOperation = (newValue, id, numberName) => {
  temblorPopularAnimation.numberOperation({id, numberName, numberValue: newValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}

const switchStatus = (statusValue, id, statusName) => {
  temblorPopularAnimation.changeStatus({id, statusName, statusValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}


const options = reactive({
  id: 'temblor_popular_animation',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: temblorPopularAnimation.getList,
  recycleApi: temblorPopularAnimation.getRecycleList,
  add: {
    show: true,
    api: temblorPopularAnimation.save,
    auth: ['temblor:popularAnimation:save']
  },
  edit: {
    show: true,
    api: temblorPopularAnimation.update,
    auth: ['temblor:popularAnimation:update']
  },
  delete: {
    show: true,
    api: temblorPopularAnimation.deletes,
    auth: ['temblor:popularAnimation:delete'],
    realApi: temblorPopularAnimation.realDeletes,
    realAuth: ['temblor:popularAnimation:realDeletes']
  },
  recovery: {
    show: true,
    api: temblorPopularAnimation.recoverys,
    auth: ['temblor:popularAnimation:recovery']
  },
  import: {
    show: true,
    url: 'temblor/popularAnimation/import',
    templateUrl: 'temblor/popularAnimation/downloadTemplate',
    auth: ['temblor:popularAnimation:import']
  },
  export: {
    show: true,
    url: 'temblor/popularAnimation/export',
    auth: ['temblor:popularAnimation:export']
  }
})

const columns = reactive([
  {
    title: " ",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入 "
    }
  },
  {
    title: "标题",
    dataIndex: "title",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入标题"
    }
  },
  {
    title: "视频",
    dataIndex: "video",
    formType: "upload",
    type: 'chunk',
    search: true,
    hide: false,
    commonRules: {
      required: true,
      message: "请输入视频"
    },
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: true,
    chunkSize: 1024 * 1024 * 8


  },
  {
    title: "封面",
    dataIndex: "cover",
    formType: "upload",
    search: true,
    commonRules: {
      required: true,
      message: "请输入封面"
    },
    onlyData: true,
    returnType: "url",
    multiple: false,
    chunk: false,
    type: "image"
  },
  {
    title: "",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default {name: 'temblor:popularAnimation'} </script>